﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;
using System.Text;
using System.Net;
using System.IO;

using Wind.MultimediaStation.WebService.Entity;

using Wind.Utils;
using Wind.Base;
using Wind.Speed;

namespace Wind.MultimediaStation.WebService
{
    public class MultimediaStationWindMarketBusiness
    {
        public OMaterialInfo QuerySpeedSharpByMaterialCode(OMaterialInfo info)
        {
            DataLines data ;

            try
            {
                data = new MultimediaStationSpeedSharpBusiness().GetSectorMDSnapshot(info.MaterialCode);
            }
            catch (Exception ex)
            {
                LogHelper.Write("Wind.MultimediaStation.WebService MultimediaStationWindMarketBusiness Error:" + info.MaterialCode.ToString() + "," + ex.Message.ToString());
                throw;
            }


            if (data != null && data.ErrorCode == SpeedErrors.NO_ERROR)
            {
                try
                {
                    string strTemp = data.Items[0].Values[1].ToString() + data.Items[0].Values[2].ToString().PadLeft(6, '0');

                    info.MaterialTime = strTemp.Substring(0, 4) + "-" + strTemp.Substring(4, 2) + "-" + strTemp.Substring(6, 2) + " " + strTemp.Substring(8, 2) + ":" + strTemp.Substring(10, 2) + ":" + strTemp.Substring(12, 2);
                    info.MaterialValue = string.Format("{0:0.00}",data.Items[0].Values[3]);
                    info.UpDownValue = string.Format("{0:0.00}",data.Items[0].Values[8]);
                    info.UpDownPercent = string.Format("{0:0.00}", double.Parse(data.Items[0].Values[9].ToString()) * 100) + "%";
                }
                catch (Exception e)
                {
                    info.MaterialTime = "";
                    info.MaterialValue = "";
                    info.UpDownValue = "";
                    info.UpDownPercent = "";
                    LogHelper.Write("Wind.MultimediaStation.WebService MultimediaStationWindMarketBusiness Error:" + info.MaterialCode.ToString() + "," + e.Message.ToString());
                }
            }
            return info;
        }
        public OMaterialInfo QuerySpeedWebByMaterialCode(OMaterialInfo info)
        {
            //string[] quoteItems = new string[] {"前收盘","今开盘", "最高价", "最低价", "最新价", "涨跌", "涨跌幅", "成交额", "上涨家数", "平盘家数", "下跌家数","日期","时间" };
            UInt32[] quoteItems = new UInt32[] { 4, 5, 6, 7, 3, 80, 81, 59, 217, 219, 218, 1, 2 };
            List<List<string>> res = RealHQHelper.GetSpeedWebQuote(quoteItems, new string[] { info.MaterialCode }, 0, 'n', 0);
            if (res != null)
            {
                string strTemp = DateTime.Now.ToString("yyyyMMddHHssmm");
                if (res[0][12].ToString() != "0")
                {
                    strTemp = res[0][12].ToString() + res[0][13].ToString().PadLeft(6, '0');
                }
                info.MaterialTime = strTemp.Substring(0, 4) + "-" + strTemp.Substring(4, 2) + "-" + strTemp.Substring(6, 2) + " " + strTemp.Substring(8, 2) + ":" + strTemp.Substring(10, 2) + ":" + strTemp.Substring(12, 2);
                info.MaterialValue = string.Format("{0:0.00}",res[0][5]);
                info.UpDownValue = string.Format("{0:0.00}",res[0][6]);
                info.UpDownPercent = string.Format("{0:0.00}",double.Parse(res[0][7]) * 100) + "%";
            }
            return info;
        }
    }
}
